{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    {include file="form" /}
    <?php use think\Db;?>
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            {tp:menu menu="deleteforever" /}
        </span>
        <form class="form form-horizontal" id="add1" method="post" onsubmit="return add_room_price()">
            <input type="hidden" name="id" value="{$vo.id ?? ''}">
            <input type="hidden" class="input-text" placeholder="酒店时间价格" name="hotel_time_price_id" value="{$hotel_time_price.id ?? ''}" >
                <label>酒店名称：</label>
            {php}
            $hotel_id = Db::name('hotel_time_price')->where('id',$id)->value('hotel_id');
            echo Db::name('hotel')->where('id',$hotel_id)->value('hotel_name');{/php}
            &nbsp;&nbsp;
                <label>酒店房型：</label>
                        <select name="room_type_id" class="input-text" style="width:200px;vertical-align: top;margin: 2px;">
                            {if empty($vo['room_type_id'])}
                            <option value="">请选择酒店的房型</option>
                            {/if}
                            {foreach $hotel_room_type as $hrt}
                            <option {if ($vo['room_type_id'] == $hrt['room_type_id'])} selected {/if} value="{$hrt.room_type_id}">{$hrt.type_name}</option>
                            {/foreach}
                        </select>
            &nbsp;&nbsp;
                <label>房间价格：</label>
                    <input type="text" class="input-text" style="width: 150px;margin: 2px;" placeholder="房间价格" name="room_price" value="{$vo.room_price ?? ''}" >

            <label>是否包含早餐：</label>
            <select name="include_breakfast" class="input-text" style="width:200px;vertical-align: top;margin: 2px;">
                <option value=''>请选择是否包含早餐</option>
                <option value='1'>是</option>
                <option value='0'>否</option>
            </select>
            &nbsp;&nbsp;
                    <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;添加&nbsp;&nbsp;</button>
            <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
        </form>

    </div>
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="th" /}
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr class="text-c">
            {include file="td" /}
            <td class="f-14">
                <a class="btn btn-primary radius mr-5" href="javascript:;" id="cancel{$vo.id}" onclick="editData(this,{$vo.id})"><i class="Hui-iconfont">&#xe647;</i>编辑</a>
                <span id="edit{$vo.id}" style="display: none;">
                    <a class="btn btn-danger radius mr-5" href="javascript:;" onclick="cancelEdit(this,{$vo.id})"><i class="Hui-iconfont">&#xe6a6;</i>取消</a>
                    <a class="btn btn-primary radius mr-5" href="javascript:;" onclick="saveData(this,{$vo.id})"><i class="Hui-iconfont">&#xe600;</i>提交</a>
                </span>
                <!--{tp:menu menu='sedit' /}-->
                {tp:menu menu='sdeleteforever' /}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>
{/block}

{block name='script'}
<script>
    function add_room_price() {

        $.ajax({
            type: "POST",
            url: "/admin/hotel_room_price/index",
            data: $('#add1').serialize(),
            success: function(data) {
                if(data.msg){
                    console.log('接收数据', data)
                    layer.msg(data.msg);
                    location.reload();
                }else{
                    layer_open('添加酒店房价','/admin/pub/role/id/1')
                }

            }
        });
        return false
    }

</script>
<script>
    // 显示编辑输入框
    function editData(obj, id) {
        // console.log('当前对象', obj);
        // 显示输入框和隐藏文字
        var wen = "#price" + id;
        var ibc = "#ibc" + id;
        var shu = "#shu" + id;
        var ib = "#ib" + id;
        $(wen).css('display','none');
        $(ibc).css('display','none');
        $(shu).css('display','inline');
        $(ib).css('display','inline');
        // 隐藏编辑按钮，显示提交和取消按钮
        var edit = "#edit" + id;
        $(edit).css('display','inline');
        $(obj).css('display','none');
    }
    // 取消编辑
    function cancelEdit(obj, id) {
        // 恢复原来的样子,隐藏输入框和显示数据
        var wen = "#price" + id;
        var ibc = "#ibc" + id;
        var shu = "#shu" + id;
        var ib = "#ib" + id;
        $(wen).css('display','inline');
        $(ibc).css('display','inline');
        $(shu).css('display','none');
        $(ib).css('display','none');
        // 显示编辑按钮，隐藏提交和取消按钮
        var edit = "#edit" + id;
        var cancel = "#cancel" + id;
        $(edit).css('display','none');
        $(cancel).css('display','inline');
    }
    // 保存数据
    function saveData(obj, id) {
        // 获取当前输入框的数值
        var shu = "#shu" + id;
        var ib = "#ib" + id;
        var price = $(shu).val();
        var include_breakfast = $(ib).val();
        // console.log('获取到的数据是：', num);
        // console.log('要提交的id是：', id);
        if (!price){
            layer.msg('房间的价格不能为空');
            return false;
        }
        $.ajax({
            type: 'post',
            url: '/admin/hotel_room_price/save',
            data: {id:id, price:price,include_breakfast:include_breakfast},
            success: function (ret) {
                if (ret.code == 1){
                    layer.msg(ret.msg)
                }else{
                    layer.msg(ret.msg);
                    location.reload();
                }
            }
        });
    }
</script>

{/block}

